//
//  YZSwineryModel.m
//  VET
//
//  Created by 刘文靖 on 2018/7/18.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZSwineryModel.h"
#import "NSDate+YZDatePickView.h"
#import "YZAutoItemModel.h"
@implementation YZSwineryModel
+ (NSDictionary *)mj_replacedKeyFromPropertyName
{
    return @{@"swineryId" : @"id"
             };
}

- (NSString *)herdBirthdateStr{
    if (!_herdBirthdateStr) {
        _herdBirthdateStr = [NSDate distanceTimeWithBeforeTime:self.herdBirthdate];
    }
    return _herdBirthdateStr;
}

//猪群1000011（商品猪/保育）
- (NSString *)swineryOptionStr{
    if (!_swineryOptionStr) {
        _swineryOptionStr = [NSString stringWithFormat:@"猪群%@  (%@/%@)",self.batchNo,self.herdClass.itemValue,kTextDefault(self.herdState.itemValue, @"未确定")];
    }
    return _swineryOptionStr;
}
@end
@implementation YZSwineryModelAPI

+ (RACSignal*)requestSwineryList:(NSInteger)index batchNo:(NSString *)batchNo{

    return [YZSwineryModelAPI requestSwineryList:index batchNo:batchNo type:nil];
}

+ (RACSignal*)requestSwineryList:(NSInteger)index batchNo:(NSString *)batchNo type:(NSString*)type{
    YZSwineryModelAPI *api = [YZSwineryModelAPI api];
    api.action = @"/api/swinery";
    api.showLoadingStatus = NO;
    [api addParam:@"index" value:@(index)];
    [api addParam:@"size" value:@(10)];
    if (batchNo) {
        [api addParam:@"batchNo" value:batchNo];
    }
    if (type) {
        [api addParam:@"type" value:type];
    }
    return [api getRequest];
}

/**删除猪群档案 */
+ (RACSignal*)deleteSwineryWithID:(NSInteger)swineryId{
    YZSwineryModelAPI *api = [YZSwineryModelAPI api];
    api.action = [NSString stringWithFormat:@"/api/swinery/%ld",(long)swineryId];
    api.showLoadingStatus = YES;
    return [api deleteRequest];
}

/** (猪群/猪只） 添加保健*/
+ (RACSignal*)addCare:(NSDictionary *)params{
    YZSwineryModelAPI *api = [YZSwineryModelAPI api];
    api.action = @"/api/care";
    [api addParams:params];
    api.showLoadingStatus = YES;
    return [api postRequest];
}

@end
